<template>
  <a-card :bordered="false">
    <div>
      <a-form @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="12" :sm="12">
            <a-form-item label="测评活动名称" :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-input v-model="queryParam.name" placeholder="请输入测评活动名称" />
            </a-form-item>
          </a-col>
          <a-col :md="12" :sm="8">
            <a-form-item>
              <a-button type="primary" icon="search" @click="searchQuery()">查询</a-button>
              <a-button type="primary" icon="reload" style="margin-left: 8px" @click="searchReset()">重置</a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <vxe-grid
        id="ActivityList"
        ref="vxeTable"
        :row-config="{keyField:'id'}"
        v-bind="options"
        v-on="listeners"
    >
      <template #action="{ row }">
        <a @click="handleEdit(row)">编辑</a>
        <a-divider type="vertical" />
        <a-dropdown>
          <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
          <a-menu slot="overlay">
            <a-menu-item>
              <a @click="handleDetail(row)">详情</a>
            </a-menu-item>
<!--            <a-menu-item>
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(row.id)">
                <a>删除</a>
              </a-popconfirm>
            </a-menu-item>-->
          </a-menu>
        </a-dropdown>
      </template>
    </vxe-grid>
    <ActivityModal @ok="modalFormOk" ref="modalForm" />
  </a-card>
</template>

<script>
import { VxeTableMixin } from '@/mixins/VxeTableMixin'
import ZDictSelectTag from '@/components/dict/ZDictSelectTag'
import ActivityModal from './modules/ActivityModal'
import {getAction} from "@/services/manage";
export default {
  name: 'ActivityList',
  mixins: [VxeTableMixin],
  components: {
    ActivityModal,
    ZDictSelectTag
  },
  data() {
    return {
      columns: [
        {type: 'checkbox', width: 40, fixed: 'left'},
        {type: 'seq', width: 40, fixed: 'left'},
        {title: '测评活动名称', field: 'name',width:300},
        {title: '测评活动描述', field: 'description',width:300},
        {title: '活动状态', field: 'state', formatter: 'dictText',width:100},
        {title: '活动创建时间', field: 'activityCreateDate',width:150},
        {title: '展示名称', field: 'displayName',width:300},
        {title: '是否展示', field: 'displayState', formatter: 'dictText',width:100},
        {title: '租户', field: 'tenantId', formatter: 'dictText',width:150},
        {title: '排序', field: 'orderNum',width:50},
        {title: '操作', field: 'operation', width: 120, fixed: 'right', slots: {default: 'action'}}
      ],
      url: {
        list: '/assessment/activity/v1/page',
        sync: '/assessment/activity/v1/sync'
      },
      customTableToolbar: {
        buttons: [
          {
            buttonRender: {
              name: 'VxeToolbarButton',
              events: {click: this.syncActivity},
              props: {title: '同步活动', icon: 'cloud-download'}
            }
          },
          { buttonRender: { name: 'VxeToolbarAdd', events: { click: this.handleAdd }}}
        ]
      }
    }
  },
  methods: {
    syncActivity() {
      getAction(this.url.sync).then(res => {
        if (res.success) {
          this.loadData();
        }
      })
    }
  }
}
</script>
